/**
 * 
 * Altera banco de dados para receber o log sem comprometer desempenho,
 * reduzindo o numero de lock's do sistema.
 * 
 * Menandro Dias
 * 09.04.2008
 * 
 */

ALTER TABLE FR_LOG_EVENT DROP CONSTRAINT PK_FR_LOG_EVENT
GO
ALTER TABLE FR_LOG_EVENT ADD LOG_ID_IDENTITY INT IDENTITY
GO
ALTER TABLE FR_LOG_EVENT ADD CONSTRAINT PK_FR_LOG_EVENT PRIMARY KEY (LOG_ID_IDENTITY)
GO
ALTER PROCEDURE DBO.SP_GEN_ID(@DESC_GENERATOR NVARCHAR(50), @VL_GENERATOR INT, @RETORNO INTEGER OUTPUT)
AS
BEGIN
	IF @DESC_GENERATOR != 'GEN_LOG' 
	BEGIN
		DECLARE @TEMP NVARCHAR(1000), @TEMP_SQL NVARCHAR(1000), @TEMP_RESULT NUMERIC(18,4), @CONT INT
		-- Leitura Suja
		SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
		BEGIN TRAN
		SET @TEMP = 'dbo.AA_GEN_' + @DESC_GENERATOR
		SET @TEMP_SQL = ' INSERT INTO ' + @TEMP + ' VALUES( ' + CAST(@@SPID AS VARCHAR(10))  + ' ) '
		EXEC SP_EXECUTESQL 	@TEMP_SQL,
							N'@TEMP_RESULT NUMERIC(18, 4) OUT',
							@TEMP_RESULT OUT
		SET @RETORNO = @@IDENTITY
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
	END
	ELSE
		SET @RETORNO = @@IDENTITY
END
GO